//
//  LCWBottomView.swift
//  MyWB
//
//  Created by 李成万 on 16/6/29.
//  Copyright © 2016年 李成万. All rights reserved.
//

import UIKit

class LCWBottomView: UIView {
    
    var status:LCWStatus?{
        didSet{
            leftBtn?.setTitle(status?.reposts_count_str, forState: .Normal)
            middleBtn?.setTitle(status?.comments_count_str, forState: UIControlState.Normal)
            rightBtn?.setTitle(status?.attitudes_count_str, forState: UIControlState.Normal)
        }
    }

    var leftBtn:UIButton?
    var middleBtn:UIButton?
    var rightBtn:UIButton?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setupUI(){
        leftBtn = createBtn("timeline_icon_retweet", name: self.status?.reposts_count_str ?? "")
        middleBtn = createBtn("timeline_icon_comment", name: self.status?.comments_count_str ?? "")
        rightBtn = createBtn("timeline_icon_unlike", name: self.status?.attitudes_count_str ?? "")
        
        addSubview(leftBtn!)
        addSubview(middleBtn!)
        addSubview(rightBtn!)
        
        
        leftBtn?.snp_makeConstraints(closure: { (make) -> Void in
            make.leading.top.bottom.equalTo(self)
            make.width.equalTo(middleBtn!)
        })
        middleBtn?.snp_makeConstraints(closure: { (make) -> Void in
            make.leading.equalTo(leftBtn!.snp_trailing)
            make.top.bottom.equalTo(self)
            make.width.equalTo(rightBtn!)
        })
        rightBtn?.snp_makeConstraints(closure: { (make) -> Void in
            make.leading.equalTo(middleBtn!.snp_trailing)
            make.top.bottom.trailing.equalTo(self)
        })
        
        let line1 : UIImageView = UIImageView(imageName: "timeline_card_bottom_line")
        let line2 : UIImageView = UIImageView(imageName: "timeline_card_bottom_line")
        addSubview(line1)
        addSubview(line2)
        
        line1.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            make.leading.equalTo(leftBtn!.snp_trailing)
        }
        line2.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            make.leading.equalTo(middleBtn!.snp_trailing)
        }
    }
    
    
    func createBtn(imageName:String,name:String) -> UIButton{
       let btn = UIButton(imageName: imageName, backgroundImageName: "timeline_card_bottom_background")
        btn.setTitle(name, forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        
        return btn
    }
    

}
